package com.gj.service.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gj.dao.UserDODao;
import com.gj.pojo.UserDO;
import com.gj.pojo.UserDOQuery;
import com.gj.service.UserDOService;
import com.gj.utils.EasyUIDataGridResult;

@Service
public class UserDOServiceImpl implements UserDOService {

	@Autowired
	private SqlSession sqlSession;

	@Override
	public UserDO selectByPrimaryKey(Integer userId) {
		UserDODao userDODao = sqlSession.getMapper(UserDODao.class);
		return userDODao.selectByPrimaryKey(userId);
	}

	@Override
	public UserDO managerDoLogin(String userPhone, String userPassword) {
		UserDODao userDODao = sqlSession.getMapper(UserDODao.class);
		return userDODao.selectByPhoneAndPass(userPhone, userPassword);
	}

	@Override
	public EasyUIDataGridResult getItemList(int page, int rows) {
		// 设置分页信息
		PageHelper.startPage(page, rows);
		// 执行查询
		UserDOQuery example = new UserDOQuery();
		UserDODao userDODao = sqlSession.getMapper(UserDODao.class);
		List<UserDO> list = userDODao.selectByExample(example);
		// 取查询结果
		PageInfo<UserDO> pageInfo = new PageInfo<>(list);
		EasyUIDataGridResult result = new EasyUIDataGridResult();
		result.setRows(list);
		result.setTotal(pageInfo.getTotal());
		// 返回结果
		return result;
	}

}
